package com.ls.fw.data.bean;

import java.util.ArrayList;
import java.util.List;

import com.ls.fw.data.utils.DataUtil;

public class MethodOrder extends Order{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//参数
	private List<KeyValue> params = new ArrayList<KeyValue>();
	//条件
	private String option;
	
	private String fieldName;
	
	private boolean dynamic = false;
	
	public MethodOrder(SortFunctions af, OrderType type) {
		super(af.getName(), type);
	}

	
	/**
	 * 自定义排序方法(即非SortFunctions识别的方法,方法标签：方法名(para1,para2,....))
	 * @param defineMethodName 方法名
	 * @param type 排序类型
	 */
	public MethodOrder(String defineMethodName, OrderType type) {
		super(defineMethodName, type);
		this.dynamic = true;
	}

	
	public MethodOrder(SortFunctions af) {
		this(af, null);
	}
	
	public MethodOrder addParam(Object value){
		this.params.add(new KeyValue(value));
		return this;
	}

	public MethodOrder addParam(String key,Object value){
		this.params.add(new KeyValue(key, value));
		return this;
	} 
	
	public List<KeyValue> getParams() {
		return params;
	}

	@Override
	public String toString() {
		if (option != null) {
			return this.name.toUpperCase() + "(" + option + " " + DataUtil.joiner(params, ",") + ")";
		}
		return this.name.toUpperCase() + "(" + DataUtil.joiner(params, ",") + ")";
	}

	public String getFieldName() {
		return fieldName;
	}

	public MethodOrder setFieldName(String fieldName) {
		this.fieldName = fieldName;
		return this;
	}

	public boolean isDynamic() {
		return dynamic;
	}

	
	/**
	 * 设置是否是自定义排序方法
	 * @author ls
	 * 2014年11月26日上午11:26:06 
	 * @param dynamic
	 * @return
	 */
	public MethodOrder setDynamic(boolean dynamic) {
		this.dynamic = dynamic;
		return this;
	}


	public String getOption() {
		return option;
	}


	/**
	 * 
	 * @author ls
	 * 2014年12月3日下午2:45:25 
	 * @param option distinct等
	 * @return
	 */
	public MethodOrder setOption(String option) {
		this.option = option;
		return this;
	}

}
